package com.treehouse.gui.mainview;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class MainView extends JFrame {

	private static final long serialVersionUID = 1L;

	private static final Dimension VIEW_SIZE = new Dimension(1000, 600);

	private static JMenuBar menuBar;

	private static JMenu fileMenu;
	private static JMenuItem fileMenuExit;

	private static JMenu editMenu;
	private static JMenuItem editMenuProperties;

	private static JMenu helpMenu;
	private static JMenuItem helpMenuAbout;

	private static JPanel leftPanel;
	private static JPanel consolePanel;

	private static JTextArea outputConsole;
	private static JTextField inputConsole;

	public MainView(String title) {
		super(title);
		this.initialize();
	}

	private void initialize() {

		this.setSize(VIEW_SIZE);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLayout(new GridLayout(1, 2));
		this.setResizable(false);

		menuBar = new JMenuBar();

		fileMenu = new JMenu("File");
		fileMenuExit = new JMenuItem("Exit");
		fileMenu.add(fileMenuExit);
		menuBar.add(fileMenu);

		editMenu = new JMenu("Edit");
		editMenuProperties = new JMenuItem("Properties");
		editMenu.add(editMenuProperties);
		menuBar.add(editMenu);

		helpMenu = new JMenu("Help");
		helpMenuAbout = new JMenuItem("About");
		helpMenu.add(helpMenuAbout);
		menuBar.add(helpMenu);

		this.setJMenuBar(menuBar);

		leftPanel = new JPanel(null);
		leftPanel.setVisible(true);

		consolePanel = new JPanel(new BorderLayout());
		consolePanel.setBorder(BorderFactory.createTitledBorder("Console"));
		consolePanel.setVisible(true);

		outputConsole = new JTextArea();
		outputConsole.setEditable(false);
		outputConsole.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		outputConsole.setAutoscrolls(true);

		inputConsole = new JTextField();
		inputConsole.setBorder(BorderFactory.createLineBorder(Color.BLACK));

		consolePanel.add(outputConsole, BorderLayout.CENTER);
		consolePanel.add(inputConsole, BorderLayout.PAGE_END);

		this.add(leftPanel);
		this.add(consolePanel);
	}

	public JTextArea getOutputConsole() {
		return outputConsole;
	}

	public JTextField getInputConsole() {
		return inputConsole;
	}

}
